<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$appConfigs.title}</title>

    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/{$page_theme | default: 'default'}/easyui.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/style/my.css">
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/javascript/my.js"></script>
    
</head> 
<body onpageshow="resetPagination('dg')">
    {datagrid id="dg" datasource="/invest/AssetsService/findAll.do" template="common/datagrid3.tpl" view="i_assets"}
    {form id="dlg" view="i_assets" }
    {form id="dlg2" view="i_assets_price" }
    
    <div id="dlg3" class="easyui-dialog" style="width:600px; height:400px;padding:10px 20px"
            closed="true" buttons="#dlg3-buttons">
        <div class="ftitle">信息</div>
        <form id="file_form" method="post" enctype="multipart/form-data" action="/invest/InvestingHistoryPriceSpider/upload.do" novalidate>
            <div class="fitem">
                <label>投资品种代码:</label>
                <input id="f-dlg3-code" name="code" class="easyui-textbox" required="true" style="width:300px" maxlength='20'>
            </div>
            <div class="fitem">
                <label>数据文件:</label>
                <input id="f-dlg3-file" name="file" type="file" required="true" style="width:300px">
            </div>
        </form>
    </div>
    <div id="dlg3-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="submitFileForm()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg3').dialog('close')" style="width:90px">取消</a>
    </div>
    <div style="position: fixed; z-index: 10000; top: 0; left: 0; right: 0; bottom: 0; height: 100%; background-color: rgba(0, 0, 0, .3); display:none;" id="js-waiting">
        <img style="position: absolute; z-index: 1000; width: 80px; height 80px; left: 50%; top: 50%; margin-left: -40px; margin-top: -40px;" src="/pas/easyui/themes/default/images/loading.gif"/>
    </div>
    
    <script>
    function submitFileForm() {
        var formData = new FormData();
        formData.append("file", $("#f-dlg3-file")[0].files[0]);
        formData.append("code", $("#f-dlg3-code")[0].value);
        $('#js-waiting').show();
        $.ajax({
            url:'/invest/InvestingHistoryPriceSpider/upload.do', /*接口域名地址*/
            type:'post',
            enctype:'multipart/form-data',
            data: formData,
            contentType: false,
            processData: false,
            success:function(res){
                if(res['ReturnCode'] == 0) {
                    $('#js-waiting').hide();
                    getDialog("dlg3").dialog('close');
                    $.messager.show({
                        title: '错误',
                        msg: "批处理修改成功"
                    });
                } else {
                    $('#js-waiting').hide();
                    getDialog("dlg3").dialog('close');
                    $.messager.show({
                        title: '错误',
                        msg: res.Msg
                    });
                }
            }
        })
    }
    field_formatters.risk_level=function (value, row, index){
		if(value == 4)
			return '<font color="red">高</font>';
		else if(value == 3)
			return '<font color="red">中高</font>';
		else if(value == 2)
			return '<font color="orange">中</font>';
		else if(value == 1)
			return '<font color="green">低</font>';
		else if(value == 0)
			return '安全';
    }
    field_formatters.status=function (value, row, index){
		if(value == 1)
			return '<font color="green">在用</font>';
		else 
			return '<font color="red">不在用</font>';
    }
    field_formatters.fellRateM3=function (value, row, index){
		if(value) {
			return '<font color="green">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.riseRateM3=function (value, row, index){
		if(value) {
			return '<font color="red">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.fellRateM6=function (value, row, index){
		if(value) {
			return '<font color="green">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.riseRateM6=function (value, row, index){
		if(value) {
			return '<font color="red">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.fellRateM12=function (value, row, index){
		if(value) {
			return '<font color="green">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.riseRateM12=function (value, row, index){
		if(value) {
			return '<font color="red">'+numberFormat(value,2)+'%</font>';
		}
    }
    field_formatters.name=function (value, row, index){
		if(row["favorited"]) {
			return value + '&nbsp;<font color="red">√</font>';
		} else {
			return value;
		}
    }
    
    function fetchPrice() {
    	$.messager.confirm('操作确认！','正准备重新抓取指数价格，可能时间较长！',function(r){
			$('#js-waiting').show();
			$.getJSON('/assets/AssetsPriceCaptureService/catchAllAssetsPrice.do', function(data){
				$('#js-waiting').hide();
				$.messager.show({
                    title: '提示',
                    msg: '价格抓取完成！'
                });
			});
        });
    }
    
    function showPriceDetail() {
	    var row = getDatagrid('dg').datagrid('getSelected');
	    if(row) {
	    	window.parent.openTab(row.name + '的价格','/invest/assets/assets_price.shtml?assets_id='+row.assets_id);
	    } else {
			alert('没有选择投资计划！');
	    }
    }

	function showPriceChart() {
	    var row = getDatagrid('dg').datagrid('getSelected');
	    if(row) {
			var dt = new Date();
			dt.setMonth( dt.getMonth()- 12);
			var ds = date_formatter(dt);
	    	window.parent.openTab(row.name + '的价格图','/invest/assets/assets_price_chart.shtml?assets_id='+row.assets_id+"&from_date="+ds+"&name="+row.name);
	    } else {
			alert('没有选择投资计划！');
	    }
	}
    </script>
</body>
</html>